package service;


import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;


import com.telkomsigma.hibernate.persistence.team.entity.Team;
import com.telkomsigma.hibernate.services.team.TeamService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
@Transactional
public class TestTeamService extends AbstractTransactionalJUnit4SpringContextTests{
	
	private Team team = new Team();
	
	@Autowired
	private TeamService teamService;	

	@Test
	public void testCheckDaoConfig() {				
		assertNotNull(teamService);		
	}


	@Test
	public void testInsertTeam(){			
		team.setName("Dream Team FC");
		
		Team result = teamService.insert(team);
		assertNotNull(result);
	}
	
	@Test
	public void testRemoveTeam(){
		team.setId("ff8080813192e553013192e556720001");
		boolean check = teamService.remove(team);
		assertTrue(check==true);
	}
	
	@Test
	public void testFindByIdTeam(){
		team.setId("ff8080813192ee1e013192ee203b0001");
		Team result = teamService.findById("ff8080813192ee1e013192ee203b0001");
		assertEquals("Dream Team FC", result.getName());
		assertNotNull(result);
	}
	
	@Test
	public void testUpdate(){
	team.setId("f8080813192e6ec013192e6eeb10001");
	team.setName("Cita-Cita FC");
	Team result = teamService.update(team);
	assertNotNull(result);
	}
	
	@Test
	public void testFindAllTeam(){		
		List<Team> teamList = teamService.findAll(0,20);
		assertTrue(teamList.size()>1);		
	}
}
